package database;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;




import database.*;

import client.ChatClient;

public class DataBaseConection {

		
		public Connection conn;
		public Statement st;
		private static final String database = "jdbc:mysql://127.0.0.1:3306/information_system";
		private static final String driver = "com.mysql.jdbc.Driver";
		private static final String DBusername = "root";
		private static final String DBpassword = "Braude";
		
		
		public DataBaseConection() throws Exception
		{
			try {
				Class.forName(driver).newInstance();
			}
			catch (Exception ex) {
				throw new Exception("Couldn't load MySQL driver: "+ex.getMessage());
			}	
			
			try {
				conn =  DriverManager.getConnection(database,DBusername,DBpassword);
				st =  conn.createStatement();
			}
			catch (SQLException ex) {
				throw new Exception ("Coudn't connect to database: "+ ex.getMessage());
			}
		}
		
		public DataBaseConection(int a) throws Exception //we need more contractor that change connection when we want to delete or update database
		{
			try {
				Class.forName(driver).newInstance();
			}
			catch (Exception ex) {
				throw new Exception("Couldn't load MySQL driver: "+ex.getMessage());
			}	
			
			try {
				conn =  DriverManager.getConnection(database,DBusername,DBpassword);
				st =  conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
			}
			catch (SQLException ex) {
				throw new Exception ("Coudn't connect to database: "+ ex.getMessage());
			}
		}
		
		
	      
		
		public static void hand(ResultSet qur) throws SQLException
		{
			
	 		while(qur.next())
	 		{
				 // Print out the values
				 System.out.println(qur.getString(1)+" ");
			} 
		}
}
